package com.mofofa.maozy.components.dialog

import android.os.Bundle
import android.view.*
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.mofofa.maozy.R
import com.mofofa.maozy.databinding.DialogMaozyWarningMessageBinding

class FcfaNoWalletWarningDialog : DialogFragment() {

    companion object {
        fun showMaozyDialog(
            fragmentManager: FragmentManager,
            cancelRes: Int = R.drawable.maozy_main_red_r4,
            listener: () -> Unit = {},
        ) {
            val dialog = FcfaNoWalletWarningDialog()
            dialog.mMaozyCancelMaozyRes = cancelRes
            dialog.mMaozyOnMaozyActionMaozyListener = listener
            dialog.showNow(fragmentManager, FcfaNoWalletWarningDialog::class.java.simpleName)
        }
    }

    lateinit var mMaozyViewMaozyBinding: DialogMaozyWarningMessageBinding

    private var mMaozyOnMaozyActionMaozyListener: () -> Unit = {}
    private var mMaozyCancelMaozyRes: Int = R.drawable.maozy_main_red_r4

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View {
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mMaozyViewMaozyBinding = DialogMaozyWarningMessageBinding.inflate(layoutInflater)
        return mMaozyViewMaozyBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initMaozySubMaozyViews()
        dialog?.setCancelable(true)
        dialog?.setCanceledOnTouchOutside(true)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_TITLE, R.style.Dialog)
    }

    override fun onStart() {
        super.onStart()

        dialog?.window?.let {
            it.attributes.gravity = Gravity.CENTER
            it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
//            it.setWindowAnimations(R.style.bottomDialogAnimation)
        }
    }

    private fun initMaozySubMaozyViews() {
        mMaozyViewMaozyBinding.cbDialogwarningmessageCancel.setOnClickListener {
            dismiss()
        }
    }
}